//
//  main.c
//  004--杨辉三角
//
//  Created by Shawn Li on 2020/5/12.
//  Copyright © 2020 Shawn. All rights reserved.
//

#include <stdio.h>
#include "stdlib.h"

//1
//1 1
//1 2 1
//1 3 3 1

//思路：
//1.默认 [i][0] = 1; [i][i] = 1;
//在 1. 完成的基础上，[i][j] = [i-1][j-1] + [i-1][j].

//二维数组输出


int** yanghuiTriangle(int row, int *resSize){
    int **result = (int **)malloc(sizeof(int*) * row);
    *resSize = row;
    
    for (int i = 0; i < row; i++) {
        result[i] = (int *)malloc(sizeof(int)*(i+1));
        result[i][0] = 1;
        result[i][i] = 1;
        
        for (int j = 1; j < i; j++) {
            result[i][j] = result[i-1][j-1] + result[i-1][j];
        }
    }
    
    return result;
}


int main(int argc, const char * argv[]) {
    // insert code here...
    printf("Hello, World!\n");
    
    int resSize;
    int **result = yanghuiTriangle(7, &resSize);
    
    for (int i = 0; i < resSize; i++) {
        printf("[");
        for (int j = 0;  j<=i; j++) {
            printf(" %d ",result[i][j]);
        }
        printf("]\n");
    }
    
    return 0;
}
